﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties.CApSLPRobotParamToMfgAttributeMapping
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties;

public class CApSLPRobotParamToMfgAttributeMapping
{
  private TxObjectList _roboticOperations = new TxObjectList();

  public TxObjectList RoboticOperations
  {
    get => this._roboticOperations;
    set => this._roboticOperations = value;
  }

  public void ConnectParameter(string roboticParam) => this.connectParameter(roboticParam);

  public void ConnectParameters(IEnumerable<string> roboticParams)
  {
    this.connectParameters(roboticParams);
  }

  public bool CanConnectParameterForSomeOperation(string roboticParam)
  {
    return this.canConnectParameterForSomeOperation(roboticParam);
  }

  public bool CanConnectSomeParameterForSomeOperation(IEnumerable<string> roboticParams)
  {
    return this.canConnectSomeParameterForSomeOperation(roboticParams);
  }

  public bool IsConnectedParameterForSomeOperation(string roboticParam)
  {
    return this.isConnectedParameterForSomeOperation(roboticParam);
  }

  public bool IsConnectedSomeParameterForSomeOperation(IEnumerable<string> roboticParams)
  {
    return this.isConnectedSomeParameterForSomeOperation(roboticParams);
  }

  public bool IsDisconnectedParameterForSomeOperation(string roboticParam)
  {
    return this.isDisconnectedParameterForSomeOperation(roboticParam);
  }

  private void connectParameter(string roboticParam)
  {
    if (!this.canConnectParameterForSomeOperation(roboticParam))
      return;
    TxApplication.ActiveUndoManager.StartTransaction();
    foreach (ITxObject roboticOperation in (Collection<ITxObject>) this._roboticOperations)
      this.connectParameter(roboticOperation as ITxRoboticOperation, roboticParam);
    TxApplication.ActiveUndoManager.EndTransaction();
  }

  private void connectParameters(IEnumerable<string> roboticParams)
  {
    if (!this.canConnectSomeParameterForSomeOperation(roboticParams))
      return;
    TxApplication.ActiveUndoManager.StartTransaction();
    foreach (string roboticParam in roboticParams)
      this.connectParameter(roboticParam);
    TxApplication.ActiveUndoManager.EndTransaction();
  }

  private void connectParameter(ITxRoboticOperation roboticOp, string roboticParam)
  {
    if (roboticOp == null || roboticParam == null || !this.canConnectParameter(roboticOp, roboticParam) || this.isConnectedParameter(roboticOp, roboticParam))
      return;
    TxRoboticParametersToMfgAttributesMappingEx.ConnectRoboticParameterToMfgAttribute(roboticOp, roboticParam);
  }

  private bool canConnectParameter(ITxRoboticOperation roboticOp, string roboticParam)
  {
    bool flag = false;
    if (roboticOp != null && roboticParam != null)
      flag = TxRoboticParametersToMfgAttributesMappingEx.CanConnectRoboticParameterToMfgAttribute(roboticOp, roboticParam);
    return flag;
  }

  private bool isConnectedParameter(ITxRoboticOperation roboticOp, string roboticParam)
  {
    bool flag = false;
    if (roboticOp != null && roboticParam != null)
      flag = TxRoboticParametersToMfgAttributesMappingEx.IsRoboticParameterConnectedToMfgAttribute(roboticOp, roboticParam);
    return flag;
  }

  private bool canConnectParameterForSomeOperation(string roboticParam)
  {
    bool flag = false;
    foreach (ITxObject roboticOperation in (Collection<ITxObject>) this._roboticOperations)
    {
      if (this.canConnectParameter(roboticOperation as ITxRoboticOperation, roboticParam))
      {
        flag = true;
        break;
      }
    }
    return flag;
  }

  private bool canConnectSomeParameterForSomeOperation(IEnumerable<string> roboticParams)
  {
    bool flag = false;
    foreach (string roboticParam in roboticParams)
    {
      if (this.canConnectParameterForSomeOperation(roboticParam))
      {
        flag = true;
        break;
      }
    }
    return flag;
  }

  private bool isConnectedParameterForSomeOperation(string roboticParam)
  {
    bool flag = false;
    foreach (ITxObject roboticOperation in (Collection<ITxObject>) this._roboticOperations)
    {
      if (this.isConnectedParameter(roboticOperation as ITxRoboticOperation, roboticParam))
      {
        flag = true;
        break;
      }
    }
    return flag;
  }

  private bool isConnectedSomeParameterForSomeOperation(IEnumerable<string> roboticParams)
  {
    bool flag = false;
    foreach (string roboticParam in roboticParams)
    {
      if (this.isConnectedParameterForSomeOperation(roboticParam))
      {
        flag = true;
        break;
      }
    }
    return flag;
  }

  private bool isDisconnectedParameterForSomeOperation(string roboticParam)
  {
    bool flag = false;
    foreach (ITxObject roboticOperation in (Collection<ITxObject>) this._roboticOperations)
    {
      if (this.canConnectParameter(roboticOperation as ITxRoboticOperation, roboticParam) && !this.isConnectedParameter(roboticOperation as ITxRoboticOperation, roboticParam))
      {
        flag = true;
        break;
      }
    }
    return flag;
  }
}
